package edu.jmu.action.sysmanage.role;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;

import edu.jmu.action.privilege.Permission;
import edu.jmu.bean.privilege.Role;
import edu.jmu.service.sysmanage.RoleService;
/**
 * 角色添加
 * @author Neal
 *
 */
@Controller 
@Namespace("/sysmanage")
@Scope(value="prototype")
public class AddRoleAction extends ActionSupport {
	private static final long serialVersionUID = -4002706370552463613L;
	
	@Resource
	private RoleService roleService;
	
	private Role role;

	@Validations(requiredStrings={
			@RequiredStringValidator(fieldName="role.name",message="角色名不能为空"),
			@RequiredStringValidator(fieldName="role.description",message="角色描述不能为空")
	},stringLengthFields={
			@StringLengthFieldValidator(fieldName="role.description",message="角色描述长度过长，因小于100个字符",maxLength="100")
	})
	@Action(value="addRole" ,results={
			@Result(name=SUCCESS,type="redirectAction",params={
					"actionName", "roleList"
			}),
			@Result(name=INPUT,location="/page/sysmanage/addRole.jsp")
	})
	@Permission(module="role",privilege="addRole")
	public String addRole(){		
		roleService.save(role);
		return SUCCESS;
	}
	
	@SkipValidation
	@Action(value="goRole",results={
			@Result(location="/page/sysmanage/addRole.jsp")
	})
	@Permission(module="role",privilege="goRole")
	public String goRole(){
		return SUCCESS;
	}
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}	
}
